import coreConstants, { SUCCESS_CODE } from '@/core/constants/coreConstants'
import { R } from '@/components/axios/interface'

class ResponseUtils {
	isSuccess(res: R<any>): boolean {
		return res?.code == SUCCESS_CODE
	}

	isFailure(res: R<any>): boolean {
		return !this.isSuccess(res)
	}

	ok<T>(data: T): R<T> {
		return {
			code: SUCCESS_CODE,
			data: data,
		} as R<T>
	}
}

export default new ResponseUtils()
